package com.seuic.hnjiningposapp.hnapps.ui.view.dialog;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ToastUtils;
import com.lxj.xpopup.core.BasePopupView;
import com.seuic.hnjiningposapp.R;
import com.seuic.hnjiningposapp.hnapps.ui.view.CEditText;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class InputNewPasswordPopup extends BasePopupView {
    Unbinder bind;

    @BindView(R.id.tv_password_title)
    TextView tvPasswordTitle;
    @BindView(R.id.edit_inputpassword)
    CEditText editInputpassword;
    @BindView(R.id.edit_inputcpassword)
    CEditText editInputcpassword;
    @BindView(R.id.import_password_gz)
    Button importPasswordGz;
    @BindView(R.id.import_password_ok)
    Button importPasswordOk;
    @BindView(R.id.import_password_layout)
    LinearLayout importPasswordLayout;
    newpassWrodCallBack mNewpassWrodCallBack;

    public InputNewPasswordPopup(@NonNull Context context, newpassWrodCallBack newpassWrodCallBack) {
        super(context);
        mNewpassWrodCallBack = newpassWrodCallBack;
    }

    @OnClick({R.id.import_password_gz, R.id.import_password_ok})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.import_password_gz:
                editInputcpassword.setText("");
                editInputpassword.setText("");
                break;
            case R.id.import_password_ok:

                if (editInputpassword.getText().toString().equals("")) {
                    ToastUtils.showLong("请输入密码");
                    return;
                }
                if (editInputcpassword.getText().toString().equals("")) {
                    ToastUtils.showLong("请再次输入密码");
                    return;
                }
                if (!editInputpassword.getText().toString().equals(editInputcpassword.getText().toString())) {
                    ToastUtils.showLong("两次输入的密码不一致。");
                    editInputcpassword.setText("");
                    editInputpassword.setText("");
                    return;
                }


                mNewpassWrodCallBack.newPsCall(editInputpassword.getText().toString());
                break;
        }
    }

    @Override
    protected int getPopupLayoutId() {
        return R.layout.inputnewpassword_popup;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        bind = ButterKnife.bind(this);
    }

    @Override
    protected void onDismiss() {
        super.onDismiss();
        //注解解绑
        if (bind != null && bind != Unbinder.EMPTY) {
            bind.unbind();
        }
        this.bind = null;
    }

    public interface newpassWrodCallBack {
        void newPsCall(String pw);
    }
}
